import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils

@allure.feature('TestCase_15: 没有播放过任何专辑时，不可进入主播放器')
@allure.issue(
    'https://www.tapd.cn/56767367/sparrow/tcase/view/1156767367001043375?url_cache_key=17e362af8b12add5e45c5e468a11c15a')
class TestCaseMusic15:
    """
    预期结果: toast文案：没有歌曲正在播放，页面不会跳转
    """

    def setup_class(self):
        XiaoMaUtils.clear_data('music')
        self.driver = init_driver()
        # 实例化页面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()

        self.music_choice_page = CommonPage(self.driver).get_music_choice_page()
        self.music_index_page = CommonPage(self.driver).get_music_index_page()
        self.music_player_page = CommonPage(self.driver).get_music_player_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('music')
        self.driver.quit()

    @allure.story("step1: 无播放数据时, 点击缩略播放器")
    @pytest.mark.run(order=151)
    def test_music_15_1_click_thumb_info(self):
        try:
            # 进入音乐
            self.launcher_index_page.click_app_list()
            self.launcher_app_list_page.click_appname(TestCase.MUSIC)
            if self.music_choice_page.is_display_title():
                self.music_choice_page.click_skip()

            # 点击缩略播放器
            self.music_index_page.click_thumb_info()

            toast_flag = self.music_index_page.is_toast_exist(text="没有歌曲正在播放")
            title_flag = self.music_index_page.is_display_online_music()
            assert toast_flag and title_flag
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == '__main__':
    pass
